From fe5ccc69a4db141c793bfa2106eacc42aa239244 Mon Sep 17 00:00:00 2001 From: robertlipe Date: Wed, 1 Jan 2014 05:30:17 +0000 Subject: [PATCH] Leak fixes (the C++ way) in mapsource. --- gpsbabel/mapsource.cc | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/gpsbabel/mapsource.cc b/gpsbabel/mapsource.cc index 27bb9fc46..687d90faa 100644 --- a/gpsbabel/mapsource.cc +++ b/gpsbabel/mapsource.cc @@ -517,8 +517,6 @@ mps_waypoint_r(gbfile* mps_file, int mps_ver, waypoint** wpt, unsigned int* mpsc { char tbuf[100]; char wptname[MPSNAMEBUFFERLEN]; - char* wptdesc = NULL; - char* wptnotes = NULL; int lat; int lon; int icon; @@ -553,7 +551,7 @@ mps_waypoint_r(gbfile* mps_file, int mps_ver, waypoint** wpt, unsigned int* mpsc gbfseek(mps_file, 8, SEEK_CUR); } - wptdesc = gbfgetcstr(mps_file); + QScopedPointerwptdesc (gbfgetcstr(mps_file)); if (gbfgetc(mps_file) == 1) { /* proximity validity */ mps_proximity = gbfgetdbl(mps_file); @@ -581,14 +579,14 @@ mps_waypoint_r(gbfile* mps_file, int mps_ver, waypoint** wpt, unsigned int* mpsc if ((mps_ver == 4) || (mps_ver == 5)) { gbfread(tbuf, 6, 1, mps_file); /* unknown */ - wptnotes = gbfgetcstr(mps_file); + QScopedPointerwptnotes (gbfgetcstr(mps_file)); + thisWaypoint->notes = *wptnotes; } else { gbfread(tbuf, 2, 1, mps_file); /* unknown */ } - thisWaypoint->shortname = xstrdup(wptname); - thisWaypoint->description = wptdesc; - thisWaypoint->notes = wptnotes; + thisWaypoint->shortname = wptname; + thisWaypoint->description = *wptdesc; thisWaypoint->latitude = GPS_Math_Semi_To_Deg(lat); thisWaypoint->longitude = GPS_Math_Semi_To_Deg(lon); thisWaypoint->altitude = mps_altitude; @@ -899,7 +897,6 @@ static void mps_route_r(gbfile* mps_file, int mps_ver, route_head** rte) { char tbuf[100]; - char* rtename; char wptname[MPSNAMEBUFFERLEN]; int lat = 0; int lon = 0; @@ -917,7 +914,7 @@ mps_route_r(gbfile* mps_file, int mps_ver, route_head** rte) double mps_altitude = unknown_alt; double mps_depth = unknown_alt; - rtename = gbfgetcstr(mps_file); + QScopedPointerrtename(gbfgetcstr(mps_file)); #ifdef MPS_DEBUG fprintf(stderr, "mps_route_r: reading route %s\n", rtename); #endif @@ -962,7 +959,7 @@ mps_route_r(gbfile* mps_file, int mps_ver, route_head** rte) #endif rte_head = route_head_alloc(); - rte_head->rte_name = rtename; + rte_head->rte_name = *rtename; route_add_head(rte_head); *rte = rte_head; @@ -1531,7 +1528,6 @@ mps_routetrlr_w_wrapper(const route_head* rte) static void mps_track_r(gbfile* mps_file, int mps_ver, route_head** trk) { - char* trkname; int lat; int lon; @@ -1545,7 +1541,7 @@ mps_track_r(gbfile* mps_file, int mps_ver, route_head** trk) (void)mps_ver; - trkname = gbfgetcstr(mps_file); + QScopedPointertrkname (gbfgetcstr(mps_file)); #ifdef MPS_DEBUG fprintf(stderr, "mps_track_r: reading track %s\n", trkname); #endif @@ -1567,7 +1563,7 @@ mps_track_r(gbfile* mps_file, int mps_ver, route_head** trk) #endif track_head = route_head_alloc(); - track_head->rte_name = trkname; + track_head->rte_name = *trkname; track_add_head(track_head); *trk = track_head; -- 2.30.2